#include "StompedReality/Base.h"
#include "StompedReality/Components/RenderInfoComponent.h"
#include "StompedReality/Core/Game.h"
#include "StompedReality/Core/Memory/ObjectPool.h"
#include <UnitTest++.h>
static const StompedReality::ID NEW_OBJECT_ID_ADD = 0x10000;
using namespace StompedReality::components;

SUITE( CONST_MEM_BLOCK )
{
  TEST( CreateTestA )
  {
    StompedReality::Game g;
    StompedReality::Core::ObjectPool<RenderInfoComponent> ms( 3 );
    StompedReality::ID idA = ms.Create( &g );
    CHECK_EQUAL( NEW_OBJECT_ID_ADD + 0, idA );
    CHECK_EQUAL( true, ms.Contains( NEW_OBJECT_ID_ADD + 0 ) );
    CHECK_EQUAL( NEW_OBJECT_ID_ADD + 0, ms.GetObjectAt( 0 )->GetID ( ));
    CHECK_EQUAL( false, ms.Contains( NEW_OBJECT_ID_ADD + 1 ) );
    CHECK( 0 == ms.GetObjectAt( 1 ));
    CHECK( 0 == ms.GetObjectAt( 2 ));
    CHECK_EQUAL( NEW_OBJECT_ID_ADD + 0, ms.GetObjectAt( 0 )->GetID ( ));
    StompedReality::ID idB = ms.Create( &g );
    CHECK_EQUAL( NEW_OBJECT_ID_ADD + 1, idB );
    CHECK_EQUAL( true, ms.Contains( NEW_OBJECT_ID_ADD + 0 ) );
    CHECK_EQUAL( true, ms.Contains( NEW_OBJECT_ID_ADD + 1 ) );
    CHECK_EQUAL( false, ms.Contains( NEW_OBJECT_ID_ADD + 2 ) );
    StompedReality::ID idC = ms.Create( &g );
    CHECK_EQUAL( NEW_OBJECT_ID_ADD + 2, idC );
    CHECK_EQUAL( true, ms.Contains( NEW_OBJECT_ID_ADD + 0 ) );
    CHECK_EQUAL( true, ms.Contains( NEW_OBJECT_ID_ADD + 1 ) );
    CHECK_EQUAL( true, ms.Contains( NEW_OBJECT_ID_ADD + 2 ) );
    CHECK_EQUAL( NEW_OBJECT_ID_ADD + 0, ms.Get( NEW_OBJECT_ID_ADD + 0 )->GetID( ) );
    CHECK_EQUAL( NEW_OBJECT_ID_ADD + 1, ms.Get( NEW_OBJECT_ID_ADD + 1 )->GetID( ) );
    CHECK_EQUAL( NEW_OBJECT_ID_ADD + 2, ms.Get( NEW_OBJECT_ID_ADD + 2 )->GetID( ) );
  }
  TEST( Delete_Test )
  {
    StompedReality::Game g;
    StompedReality::Core::ObjectPool<RenderInfoComponent> ms( 3 );
    CHECK_EQUAL( false, ms.IsObjectAt( 0 ));
    CHECK_EQUAL( false, ms.IsObjectAt( 1 ));
    CHECK_EQUAL( false, ms.IsObjectAt( 2 ));
    CHECK( 0 == ms.GetObjectAt( 0 ));
    CHECK( 0 == ms.GetObjectAt( 1 ));
    CHECK( 0 == ms.GetObjectAt( 2 ));

    StompedReality::ID idA = ms.Create( &g );
    CHECK_EQUAL( true, ms.IsObjectAt( 0 ));
    CHECK_EQUAL( false, ms.IsObjectAt( 1 ));
    CHECK_EQUAL( false, ms.IsObjectAt( 2 ));
    CHECK( 0 != ms.GetObjectAt( 0 ));
    CHECK( 0 == ms.GetObjectAt( 1 ));
    CHECK( 0 == ms.GetObjectAt( 2 ));

    StompedReality::ID idB = ms.Create( &g );
    CHECK_EQUAL( true, ms.IsObjectAt( 0 ));
    CHECK_EQUAL( true, ms.IsObjectAt( 1 ));
    CHECK_EQUAL( false, ms.IsObjectAt( 2 ));
    CHECK( 0 != ms.GetObjectAt( 0 ));
    CHECK( 0 != ms.GetObjectAt( 1 ));
    CHECK( 0 == ms.GetObjectAt( 2 ));

    RenderInfoComponent* cmpB = ms.Get( idB );
    cmpB->SetLayer( 5 );
    CHECK_EQUAL( true, ms.Contains( idA ));
    CHECK_EQUAL( true, ms.Contains( idB ));
    CHECK_EQUAL( 5, cmpB->GetLayer( ));
    ms.Remove( idA );
    CHECK_EQUAL( false, ms.IsObjectAt( 0 ));
    CHECK_EQUAL( true, ms.IsObjectAt( 1 ));
    CHECK_EQUAL( false, ms.IsObjectAt( 2 ));
    CHECK( 0 == ms.GetObjectAt( 0 ));
    CHECK( 0 != ms.GetObjectAt( 1 ));
    CHECK( 0 == ms.GetObjectAt( 2 ));

    CHECK_EQUAL( false, ms.Contains( idA ));
    CHECK_EQUAL( true, ms.Contains( idB ));

    StompedReality::ID idC = ms.Create( &g );
    CHECK_EQUAL( false, ms.IsObjectAt( 0 ));
    CHECK_EQUAL( true, ms.IsObjectAt( 1 ));
    CHECK_EQUAL( true, ms.IsObjectAt( 2 ));
    CHECK( 0 == ms.GetObjectAt( 0 ));
    CHECK( 0 != ms.GetObjectAt( 1 ));
    CHECK( 0 != ms.GetObjectAt( 2 ));

    StompedReality::ID idD = ms.Create( &g );
    CHECK_EQUAL( true, ms.IsObjectAt( 0 ));
    CHECK_EQUAL( true, ms.IsObjectAt( 1 ));
    CHECK_EQUAL( true, ms.IsObjectAt( 2 ));
    CHECK( 0 != ms.GetObjectAt( 0 ));
    CHECK( 0 != ms.GetObjectAt( 1 ));
    CHECK( 0 != ms.GetObjectAt( 2 ));

    CHECK_EQUAL( true, ms.Contains( idC ));
    CHECK_EQUAL( true, ms.Contains( idD ));
    RenderInfoComponent* cmpBB = ms.Get( idB );
    CHECK_EQUAL( 5, cmpBB->GetLayer( ));
  }
}